package com.cloud.messenger.client;


import com.cloud.messenger.api.MessageInfo;
import com.cloud.messenger.configuration.MessengerConfiguration;
import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@Data
@Slf4j
public class YunpianMessageClient implements MessengerClient {

    private String client;

    private MessengerConfiguration.YunpianProperties yunpianProperties;

    public YunpianClient init(){
        YunpianClient yunpianClient = new YunpianClient(yunpianProperties.getApikey()).init();
        return yunpianClient;
    }

    @Override
    public void send(MessageInfo messageInfo) {
        YunpianClient yunpianClient= init();
        Map<String, String> params2 = new HashMap<>();
        params2.put(YunpianClient.APIKEY, yunpianProperties.getApikey());
        params2.put(YunpianClient.MOBILE, messageInfo.getMessageDestination().getMessageTo());
        params2.put(YunpianClient.TEXT, messageInfo.getMessageContent().toString());
        Properties properties = new Properties();
        properties.setProperty("yp.version", yunpianProperties.getVersion());
        yunpianClient.getConf().with(properties);
        Result<SmsSingleSend> smsSingleSendResult = yunpianClient.init().sms().single_send(params2);
        log.info("smsSingleSendResult:{}", smsSingleSendResult);
    }




}
